<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-cn" lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="all" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta name="classification" content="" />
<meta name="author" content="" />
<meta name="copyright" content="" />
<script type="text/javascript" src="js/common.js"></script>
</head>
<body>
<script type="text/javascript">
var g_brand_tree = null;
var g_category_tree = null;
function addChildToForm(name, value, form)
{
    if ( typeof name != "string" || typeof value != "string" || typeof form == "undefined" )
    {
        return false;
    }
    var input = document.createElement("input");
    input.name = name;
    input.value = value;
    form.appendChild(input);
}
function changeBrandSelect(selectedIndex)
{
    if (typeof selectedIndex == "undefined")
    {
        return false;
    }

    var obj_select_b = $O("goods_category_b");
    var category_id  = obj_select_b.options[selectedIndex].value;
    var arr_brand = g_brand_tree[category_id];
    
    if (typeof arr_brand == "undefined")
    {
        return false;
    }
    var obj_select_brand = $O("goods_brand");
    select_removeAllOption(obj_select_brand);
    for (var i = 0; i < arr_brand.length; ++i)
    {
        select_addOption(obj_select_brand, arr_brand[i].brandName, arr_brand[i].brandId);
    }
    //alert(g_json_data[selectedIndex-1].self.category_name);
}
function changeSubCategorySelect(selectedIndex)
{
    if (typeof selectedIndex == "undefined")
    {
        return false;
    }
    var arr_category = new Array();
    for (var i = 0; i < g_category_tree[selectedIndex-1].child.length; ++i)
    {
        getSubCategory(g_category_tree[selectedIndex-1].child[i], arr_category);
    }
   
    var obj_select_brand = $O("goods_brand");
    select_removeAllOption(obj_select_brand);
    var obj_select_b = $O("goods_category_b");
    select_removeAllOption(obj_select_b);
    for (var i = 0; i < arr_category.length; ++i)
    {
        select_addOption(obj_select_b, arr_category[i].category_name, arr_category[i].category_id);
    }
    //alert(g_json_data[selectedIndex-1].self.category_name);
}

function select_removeAllOption(obj_select)
{
    if (typeof obj_select == "undefined")
    {
        return false;
    }
    while (obj_select.options.length > 1)
    {
        obj_select.remove(1);
    }
    return true;
}
function getSubCategory(category, arr_category)
{
    if (typeof category == "undefined" || typeof category.self == "undefined")
    {
        return false;
    }
    arr_category.push(category.self);
    if (category.child.length == 0)
    {
        return false;
    }
    else
    {
        for (var i = 0; i < category.child.length; ++i)
        {
            arr_category.push(category.child[i]);
        }
    }
}
function select_addOption(objSelectNow,txt,val){var objOption = parent.document.createElement("OPTION");objOption.text= txt;objOption.value=val;objSelectNow.options.add(objOption);}
function generateBrandTree()
{
    var obj_form = $O("brand_form");
    obj_form.action = "http://localhost/jiajia/nanbeihuo/index.php?controller=brand&action=generatebrandtree";
    obj_form.method = "post";
    addChildToForm("callback", "generateBrandTreeCallback", obj_form);
    obj_form.submit();
    
    return false;
}
function generateBrandGoodsJSON()
{
    var obj_form = $O("brand_form");
    obj_form.action = "http://localhost/jiajia/nanbeihuo/index.php?controller=brand&action=generatebrandgoodsjson";
    obj_form.method = "post";
    var obj_select_brand = $O("goods_brand");
    if (obj_select_brand.options[obj_select_brand.selectedIndex].value == "select_brand")
    {
        return false;
    }
    else
    {
        var brand = obj_select_brand.options[obj_select_brand.selectedIndex].value;
    }
    addChildToForm("brand_id", brand, obj_form);
    addChildToForm("callback", "generateBrandGoodsJSONCallback", obj_form);
    obj_form.submit();

    return false;
}
</script>
<h5>品牌JSON数据</h5>
<button onclick="generateBrandTree();return false;">品牌JSON</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button onclick="generateBrandGoodsJSON();return false;">品牌商品JSON</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button onclick="generateBrandTree();return false;">导出xls</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button onclick="generateBrandTree();return false;">xls导入</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button onclick="generateBrandTree();return false;">保存</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button onclick="generateBrandTree();return false;">同步</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br/>
<br/>
<form id = "brand_form" name="brand_form" method="post">
<select id="goods_category_a" onchange="if (this.selectedIndex) changeSubCategorySelect(this.selectedIndex);"><option value="root_category" id="root">root</option></select><select id="goods_category_b" onchange="if (this.selectedIndex) changeBrandSelect(this.selectedIndex);"><option value="select_category" id="select_category">请选择所属类目</option></select><select id="goods_brand" ><option value="select_brand" id="select_brand">请选择所属品牌</option></select>
<br/>
<br/>
</form>
<br/>
<script type="text/javascript">
function fillAct(json_data, json_name)
{
    if (typeof json_data == "undefined" || typeof json_name != "string")
    {
        return false;
    }
    if (json_name.match(/category_tree/))
    {
        g_category_tree = json_data;
    }
    else if (json_name.match(/brand_tree/))
    {
        g_brand_tree = json_data;
    }
    else
    {
        return false;
    }
    var len = json_data.length;
    var obj_select_a = $O("goods_category_a");
    for ( var i = 0; i < len; ++i )
    {
        select_addOption(obj_select_a, json_data[i].self.category_name, json_data[i].self.category_id );
    }
}
</script>
<script type="text/javascript" src="http://localhost/jiajia/nanbeihuo/json/json_category_tree.js"></script>
<script type="text/javascript" src="http://localhost/jiajia/nanbeihuo/json/json_brand_tree.js"></script>
</body>
</html>